<template>
  <div>
    <div class="title">
      <span>{{agentName}}-- 服务商交易统计详情</span>
      <div>
        <el-button type="primary" :disabled="exxxx" @click="merchantexcel"><i class="el-icon-download"></i>导出</el-button>
        <el-button icon="el-icon-refresh" @click="refresh"></el-button>
      </div>
    </div>
    <div class="container">
      <div class="tableBox">
        <el-table
          :header-cell-style="{color:'#606266'}"
          :data="channellistarr"
          border
          tooltip-effect="dark"
          style="width: 100%"
          @selection-change="handleSelectionChange"
          stripe
        >
           <el-table-column type="index" align="center" label="序号"></el-table-column>
          <el-table-column type="selection"></el-table-column>
          <el-table-column prop="merchantNo" align="center" label="商户号"></el-table-column>
          <el-table-column prop="merchantName" align="center" label="商户名"></el-table-column>
          <el-table-column align="center" prop="totalFee" label="交易金额"></el-table-column>
          <el-table-column align="center" prop="wxTotalFee" label="微信"></el-table-column>
          <el-table-column align="center" prop="aliTotalFee" label="支付宝"></el-table-column>
          <el-table-column align="center" prop="uniTotalFee" label="云闪付"></el-table-column>
          <el-table-column align="center" prop="bankTotalFee" label="银行卡"></el-table-column>
          <el-table-column align="center" prop="bestpayTotalfee" label="翼支付"></el-table-column>
          <el-table-column align="center" prop="ecnyTotalfee" label="数字人民币"></el-table-column>
          <el-table-column align="center" prop="longpayTotalfee" label="龙支付"></el-table-column>
          <el-table-column align="center" prop="total" label="交易笔数"></el-table-column>
          <el-table-column align="center" prop="wxTotalCount" label="微信"></el-table-column>
          <el-table-column align="center" prop="aliTotalCount" label="支付宝"></el-table-column>
          <el-table-column align="center" prop="uniTotalCount" label="云闪付"></el-table-column>
          <el-table-column align="center" prop="bankTotalCount" label="银行卡"></el-table-column>
          <el-table-column align="center" prop="bestpayTotalCount" label="翼支付"></el-table-column>
          <el-table-column align="center" prop="ecnyTotalCount" label="数字人民币"></el-table-column>
          <el-table-column align="center" prop="longpayTotalCount" label="龙支付"></el-table-column>
          <el-table-column align="center" prop="profit" label="总分润"></el-table-column>
         
        </el-table>
        <div class="pagination">
          <el-pagination
            @current-change="handleCurrentChange"
            @size-change="sizechange"
            :page-sizes="[10,20,30,40,50]"
            :page-size="cur_size"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total1"
          ></el-pagination>
        </div>
      </div>
      <br>
      <br>
    
    </div>
  </div>
</template>

<script>
import { getMerchantProfits,profitdetailexcel } from "@/api/api";
export default {
  // name: "baseform",
  data: function() {
    return {
      agentId: '',
      // agentType: this.$route.query.no.agentType,
      agentType: '',
      agentName: '',
      ctime: [],
      cur_page: 1,
      cur_size: 10,
      total1: 0,
      multipleSelection: [],
      channellistarr:[],
      pageCount:"",
      keywords:"",
      visible: false,
      exxxx: false,
      storesinfo:{
        stardate:"",
        enddate:"",
        channelno:""
      },
      info:{},
      value9: [],
    };
  },
  watch:{   //监听路由变化

  },
  created() {
    var aaa = sessionStorage.getItem('servicedeal_ctime')
    var bbb = aaa.split(',')
    this.ctime = bbb
    this.agentId = sessionStorage.getItem('servicedeal_agentId')
    this.agentType = sessionStorage.getItem('servicedeal_agentType')
    this.agentName = sessionStorage.getItem('servicedeal_agentName')
    this.channellist()
    
  },
  mounted() {
  },
  methods: {
    // 刷新
    refresh() {
      this.$router.go({
        path: 0,
        query: {
          t: Date.now()
        }
      })
    },
    // 分页导航
    handleCurrentChange(val) {
      this.cur_page = val;
      this.channellist()
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });
    },
     // 分页数量
    sizechange(val){
      this.cur_size = val
      this.channellist()
       
       this.$nextTick(() => {
         document.querySelectorAll('.content')[0].scrollTop = '0'
      });
       
    },

    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    // 渠道列表
    channellist(){
       getMerchantProfits({
          page: this.cur_page,
          size: this.cur_size,
          startDate: this.ctime[0],
          endDate: this.ctime[1],
          agentId: this.agentId,
          agentType: this.agentType
        }).then(res => {
          console.log(res);
          if(res.code == 405){
            sessionStorage. removeItem('token')
            this.$router.push('/login');
          }else{
            this.channellistarr = res.data
            this.total1 = res.pageInfo.recordCount
          }
        });
    },
    //导出
    merchantexcel(){
      this.exxxx = true;
        const loading = this.$loading({
          lock: true,
          text: 'Loading',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        profitdetailexcel({
          startDate: this.ctime[0],
          endDate: this.ctime[1],
          agentId: this.agentId,
          agentType: this.agentType
        }).then(res => {
          if(res.data.code == 405){
            sessionStorage. removeItem('token')
            this.$router.push('/login');
            loading.close();
            this.exxxx = false;
          }else if(res.data.code == 200){
        let elink = document.createElement('a');
        elink.download = "服务商交易统计.xls";
        elink.href = res.data.data;
        elink.click();
        loading.close();
        this.exxxx = false;
        }else{
          this.$message.error(res.data.message);
          loading.close();
          this.exxxx = false;
        }
      })
    }
  },
 
};
</script>
<style scoped lang="less">
.title {
  background: #fff;
  padding: 10px 10px;
  font-size: 18px;
  font-weight: 500;
  display: flex;
  justify-content: space-between;
}
.name {
  width: 25%;
}

.tableBox {
  margin-top: 20px;
  width: 100%;
}

.red {
  color: #f9607d;
}

.my-autocomplete {
  li {
    line-height: normal;
    padding: 7px;

    .name {
      text-overflow: ellipsis;
      overflow: hidden;
    }
    .addr {
      font-size: 12px;
      color: #b4b4b4;
    }

    .highlighted .addr {
      color: #ddd;
    }
  }
}
.el-table .warning-row {
    background: oldlace;
  }

</style>